﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Input;


namespace HA.ModFlow.Application
{
    /// <summary>
    /// 设计用于视图有关操作的封装
    /// </summary>
   public class RViewOperationViewModel:HViewModel
    {


       public RViewOperationViewModel()
       {

           //由于我们认为viewmodel是在项目之后诞生的，所以我们为子元素做一些变化
           if (ProjectService.DefaultService.BNullProj)
           {
               return;

           }


           if (ProjectService.DefaultService.Project.Grid3dData.MainGrid != null)
           {
               this.MinGridVM = new MiniGridViewModel(ProjectService.DefaultService.Project.Grid3dData.MainGrid);


           }
           else
           {
               this.MinGridVM = new MiniGridViewModel(null);
           }

           ProjectService.DefaultService.Project.Grid3dData.CollectionChanged += new EventHandler<Data.CollecionChangedEventArgs>(Grid3dData_CollectionChanged);
 


           //初始化工具栏

           this._toolVM = new RGToolViewModel();


       }



       #region 公共属性


       #region 视图部分

       bool _view2D = true;

       public bool View2D
       {
           get { return _view2D; }
           set
           {

               if (this._view2D != value)
               {

                   _view2D = value;

                   this.OnSetView2D();

               }


           }
       }

       protected void OnSetView2D()
       {
           this.OnPropertyChanged("View2D");

       }


       ICommand _view2d3dCommand;

       public ICommand View2d3dCommand
       {
           get {

               if (this._view2d3dCommand == null)
               {
                   _view2d3dCommand = new RelayCommand(m=>this.SetView2d3d());
                   
               }
               
               return _view2d3dCommand; }
           set { _view2d3dCommand = value; }

       }



       public  void SetView2d3d()
       {
           UIModule.DefaultModule.RendererViewModel.View2D =UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.View2D;

       }


       MiniGridViewModel _minGridVM;

       public MiniGridViewModel MinGridVM
       {
           get { return _minGridVM; }
           set
           {

               _minGridVM = value;

               this.OnPropertyChanged("MinGridVM");

           }
       }




       RGToolViewModel _toolVM;

       public RGToolViewModel ToolVM
       {
           get { return _toolVM; }
           set { _toolVM = value; }
       }





       #endregion




       #endregion



        #region commands




        #endregion





       void Grid3dData_CollectionChanged(object sender, Data.CollecionChangedEventArgs e)
       {
           switch (e.Type)
           {
               case HA.Data.CollectionChangedType.ADD:


                   this.MinGridVM.Grid = (ProjectService.DefaultService.Project.Grid3dData.MainGrid);




                   break;
               case HA.Data.CollectionChangedType.REMOVE:

                   this.MinGridVM.Grid = null;


                   break;
               case HA.Data.CollectionChangedType.MOVE:
                   break;
               case HA.Data.CollectionChangedType.REPLACE:

                   this.MinGridVM.Grid = (ProjectService.DefaultService.Project.Grid3dData.MainGrid);


                   break;
               case HA.Data.CollectionChangedType.RESET:
                   break;
               default:
                   break;
           }
       }



    }
}
